import {delCookie, getCookie, getParameter, setCookie} from 'as-common'
import store from '../store/store'
import {LoginType} from "../env/Constants";

const SITE = `web-hft-ee/`
const keys = {
  KEY_AUTH: `${SITE}auth`,
  KEY_LOGIN_TYPE: `${SITE}loginType`,
  KEY_USER_INFO: `${SITE}userInfo`,
  KEY_ENTERPRISE_INFO: `${SITE}enterpriseInfo`,
  KEY_ENTERPRISE_ROLE_INFO: `${SITE}enterpriseRoleInfo`,
  KEY_WX_USER_INFO: `${SITE}wxUserInfo`,
  KEY_SIGN: `${SITE}key_sign`,
}

function generateKey (key) {
    return `${key}`
}

const _save = (key, value) => setCookie(generateKey(key), value, 'd1', true)
const _get = (key) => getCookie(generateKey(key), true)

export default {
  keys,
  get: (key) => _get(key),
  clearAll: () => {
    Object.values(keys).forEach((key) => {
      delCookie(generateKey(key), true);
     // delCookie(LoginType.jumpAfterLogin,true)
    })
  },
  saveAuth: (auth) => _save(keys.KEY_AUTH, auth),
  saveLoginType: (type) => _save(keys.KEY_LOGIN_TYPE, type),
  saveUser: (user) => _save(keys.KEY_USER_INFO, user),
  saveEnterPrise: (data) => _save(keys.KEY_ENTERPRISE_INFO, data),
  saveEnterPriseRole: (data) => _save(keys.KEY_ENTERPRISE_ROLE_INFO, data),
  saveWxInfo: (data) => _save(keys.KEY_WX_USER_INFO, data),
  saveSign: (sign) => _save(keys.KEY_SIGN, sign),
  getSign: () => _get(keys.KEY_SIGN)
}
